package com.ddwl.gate.util;

import com.ddwl.common.service.RedisService;
//import com.ddwl.schema.rpc.gate.PushReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 极光推送
 *
 * @author Fu Zhaohui
 * @date 2015/1/22
 */
@Slf4j
@Component
public class JPushSender {


    /*@Value("${spring.profiles.active}")
    private String activeProfile;
    @Autowired
    private RedisService redisService;

    public void send(PushReq request) {
      *//*  String sound = request.getSound();
        if (!StringUtils.hasText(sound)) {
            sound = "default";
        }
        Map<String, String> config = redisService.getHashOps().entries(RedisKey.JPUSH_KEY.getKey(request.getProduct()));
        String appKey = config.get("appKey");
        String appSecret = config.get("appSecret");
        List<String> registrationIds = request.getRegistrationIdsList();
        List<String> userIds = request.getUserIdsList();
        Audience audience;
        if (registrationIds != null && !registrationIds.isEmpty()) {
            audience = Audience.registrationId(registrationIds);
        } else if (userIds != null && !userIds.isEmpty()) {
            audience = Audience.alias(userIds);
        } else {
            audience = Audience.all();
        }
        JPushClient jpushClient = new JPushClient(appSecret, appKey);
        PushPayload pushPayload = PushPayload.newBuilder().setPlatform(Platform.android_ios())
                .setAudience(audience)
                .setNotification(Notification.newBuilder()
                        .addPlatformNotification(IosNotification.newBuilder()
                                .incrBadge(1)
                                .setAlert(request.getAlert())
                                .setSound(sound)
                                .autoBadge()
                                .addExtras(request.getFieldsMap()).build())
                        .addPlatformNotification(AndroidNotification.newBuilder()
                                .setAlert(request.getAlert())
                                .setTitle(Optional.ofNullable(request.getTitle()).orElse(request.getAlert()))
                                .setStyle(3)
                                .setBigPicPath("https://ddwl.oss-cn-shanghai.aliyuncs.com/icon/favicon-192.png")
                                .addExtras(request.getFieldsMap())
                                .build())
                        .build())
                .setOptions(Options.newBuilder()
                        .setApnsProduction(activeProfile.equals("prod"))
                        .build()).build();

        try {
            jpushClient.sendPush(pushPayload);
        } catch (Exception e) {
            log.error("推送异常", e);
        }*//*
    }*/
}
